import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../common/ObjCreate";
import { GuildVipItem } from "../GuildVipItem";
import { Language } from "../../../../../extend/language/Language";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GuildUnionInviteRenderInfo } from "./GuildUnionInviteRenderInfo";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { EVIPType } from "../../../../../Message/Public/EVIPType";
import { GuildUnionPosition } from "./rule/GuildUnionPosition";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { NumInput } from "../../common/NumInput";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { _second } from "../../../../../this/_second";
//class GuildUnionInviteGuildRenderer
    
    export  class GuildUnionInviteGuildRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            var loc1=GlobalStyle.getTextFormatDefaultFont(GlobalStyle.textFormat1);
            loc1.color = GlobalStyle.color1Uint;
            this._guildName = ObjCreate.createGTextField("丐帮打天下", 10, 7, 150, 20, this, loc1);
            this._leaderName = ObjCreate.createGTextField("无崖子", 158, 7, 150, 20, this, loc1);
            this._vipItem = new GuildVipItem();
            this._vipItem.x = 118;
            this._vipItem.y = 10;
            this.addChild(this._vipItem);
            this._noVipTxt = ObjCreate.createTextField(Language.getString(30085), 118, 7, 220, 20, this, GlobalStyle.textFormat6);
            loc1.color = 16776960;
            this._camp = ObjCreate.createGTextField("星辰", 281, 7, 150, 20, this, loc1);
            loc1.color = GlobalStyle.color1Uint;
            this._guildLevel = ObjCreate.createGTextField("2", 355, 7, 150, 20, this, loc1);
            this._menberNum = ObjCreate.createGTextField("32/40", 422, 7, 150, 20, this, loc1);
            this._incomeLocate = ObjCreate.createNumInput(485, 8, this, 1, 99);
            this._incomeLocate.width = 86;
            this._incomeLocate.height = 18;
            this._incomeLocate.addEventListener(flash.events.Event.CHANGE, this.onNumInputChangeHandler);
            loc1.font = FontUtil.stXingkaiName;
            loc1.color = GlobalStyle.color6Uint;
            loc1.size = 16;
            loc1.bold = true;
            ObjCreate.createGTextField("%", this._incomeLocate.x + this._incomeLocate.width, this._incomeLocate.y, 40, 20, this, loc1);
            this._operBtn = ObjCreate.createGButton(Language.getString(60869), 600, 5, 70, 24, this);
            this._operBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOperBtnClickHandler);
            this._operBtn.drawNow();
            this._okBtn = ObjCreate.createGButton(Language.getString(69912), 585, 5, 49, 24, this);
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOperBtnClickHandler);
            this._okBtn.drawNow();
            this._okBtn.visible = false;
            this._cancelBtn = ObjCreate.createGButton(Language.getString(69913), 635, 5, 49, 24, this);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOperBtnClickHandler);
            this._cancelBtn.drawNow();
            this._cancelBtn.visible = false;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            var loc1=arg1 as GuildUnionInviteRenderInfo;
            if (loc1) 
            {
                this._guildName.htmlText = loc1.guildName;
                this._leaderName.htmlText = loc1.leaderName;
                this._camp.htmlText = GameDefConfig.instance.getECamp(loc1.camp);
                this._guildLevel.htmlText = loc1.level.toString();
                this._menberNum.htmlText = loc1.playerNum + "/" + loc1.maxPlayerNum;
                this._vipItem.vip = loc1.leaderVIP;
                if (loc1.leaderVIP != EVIPType._EVIPTypeNormal) 
                {
                    this._noVipTxt.visible = false;
                }
                else 
                {
                    this._noVipTxt.visible = true;
                }
                this._incomeLocate.maxNum = loc1.allocateMax;
                this._incomeLocate.currentNum = loc1.allocate;
                this._second = loc1.position == GuildUnionPosition.GuildUnionPositionTwo;
                if (loc1.position != GuildUnionPosition.GuildUnionPositionOne) 
                {
                    this._incomeLocate.editable = true;
                    this._operBtn.visible = true;
                    this._okBtn.visible = false;
                    this._cancelBtn.visible = false;
                    if (loc1.hasUnion) 
                    {
                        this._operBtn.label = Language.getString(60881);
                    }
                    else 
                    {
                        this._operBtn.label = Language.getString(60869);
                    }
                }
                else 
                {
                    this._incomeLocate.editable = false;
                    this._operBtn.visible = false;
                    this._okBtn.visible = true;
                    this._cancelBtn.visible = true;
                }
                this._operBtn.enabled = loc1.isCanOperate;
                this._operBtn.drawNow();
                this._okBtn.enabled = loc1.isCanOperate;
                this._okBtn.drawNow();
                this._cancelBtn.enabled = loc1.isCanOperate;
                this._cancelBtn.drawNow();
            }
            return;
        }

        /* internal  */onNumInputChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=data as GuildUnionInviteRenderInfo;
            if (loc1) 
            {
                loc1.allocate = this._incomeLocate.currentNum;
            }
            return;
        }

        /* internal  */onOperBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=data as GuildUnionInviteRenderInfo;
            if (loc1) 
            {
                var loc2=arg1.target;
                switch (loc2) 
                {
                    case this._operBtn:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionDoInvite, {"guild": loc1, "allocate": this._incomeLocate.currentNum, "second": _second}));
                        break;
                    }
                    case this._okBtn:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionDoAcceptInvite, loc1));
                        break;
                    }
                    case this._cancelBtn:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionDoRejectInvite, loc1));
                        break;
                    }
                }
            }
            return;
        }

        /* internal */ /* var */_guildName: GTextFiled;

        /* internal */ /* var */_leaderName: GTextFiled;

        /* internal */ /* var */_camp: GTextFiled;

        /* internal */ /* var */_guildLevel: GTextFiled;

        /* internal */ /* var */_menberNum: GTextFiled;

        /* internal */ /* var */_incomeLocate: NumInput;

        /* internal */ /* var */_vipItem: GuildVipItem;

        /* internal */ /* var */_noVipTxt: GTextFiled;

        /* internal */ /* var */_operBtn: GButton;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_second: Boolean;
    }
